#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime_api.h>
#include "include.h"
#include "heap.h"
#include "maze.h"
#include "stl_heap.h"


//***************************
//			Auxiliar
//***************************

//Copy stuff
void CopyToGpu();
void CopyToCpu();

//Free Stuff
void FreeCpu();
void FreeGpu();


//***************************
//			GPU STUFF
//***************************
#define BLOCK_SIZE		512

dim3  dimGrid, dTthreads;

//The best one for me:
struct d_cell{
	cell move[DIRECTIONS];
    cell succ[DIRECTIONS];
    cell searchtree;
    cell trace;
    short obstacle;
    int x, y;
    int dfsx, dfsy;
    int g;
    int rhs;
    int key[3];
    int generated;
    int heapindex;
} typedef d_cell;

//See if you really need this on the gpu for all threads
d_cell **d_mainMaze;
d_cell **d_agentMaze;

void InitGPU(int resX, int resY);

__global__ void kernel(d_cell **d_maze);


//***************************
//		CPU STUFF
//***************************

//The best one for me:
struct h_cell{
	cell move[DIRECTIONS];
    cell succ[DIRECTIONS];
    cell searchtree;
    cell trace;
    short obstacle;
    int x, y;
    int dfsx, dfsy;
    int g;
    int rhs;
    int key[3];
    int generated;
    int heapindex;
} typedef h_cell;


h_cell **h_mainMaze;
h_cell **h_agentMaze;
 

int main(void){
	//Init the maze
	//Init cpu variables
	//InitCpu();
	
	//Init the Gpu drivers
	//InitGPU(10, 10);
	//KernelCall
	//kernel <<<dimGrid, dTthreads>>>(d_maze);
	
	//Need to get back everything you want
	//CopyToCpu();
	
	//Free all stuff
	//FreeGpu();
	//FreeCpu();
	return 0;
}

void InitGPU(int resX, int resY){
	// Calculando variáveis do CUDA
	unsigned int widthInBlocks,
	heightInBlocks,
	
	
	CHECK_ERROR(cudaSetDevice(1));
	widthInBlocks = (resX / BLOCK_SIZE);
	heightInBlocks = (resY / BLOCK_SIZE);
	
	dimGrid.x = widthInBlocks;
	dimGrid.y = heightInBlocks;
	
	dTthreads.x = BLOCK_SIZE;
	dTthreads.y = BLOCK_SIZE;
	
	CopyToGpu();
	
	//CHECK_ERROR(cudaThreadSynchronize());
}

__global__ void kernel(d_cell **d_maze){
	
}

void CopyToGpu(){
//	CHECK_ERROR(cudaMalloc((void**) &d_mainMaze, sizeof(d_mainMaze)*MAZEHEIGHT));
//	CHECK_ERROR(cudaMemcpy(d_mainMaze, h_mainMaze, sizeof(d_mainMaze)*MAZEHEIGHT, cudaMemcpyHostToDevice));
}

void CopyToCpu(){
//	CHECK_ERROR(cudaMemcpy(d_mainMaze, h_mainMaze, sizeof(d_mainMaze)*MAZEHEIGHT, cudaMemcpyDeviceToHost));
}

void FreeGpu(){
	cudaFree(d_mainMaze);
}


void FreeCpu(){
	
}

